package com.cqemme.comm.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import java.beans.BeanInfo;
import java.io.*;
import java.lang.reflect.Field;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author 86156
 */
@SuppressWarnings({"ALL", "AlibabaConstantFieldShouldBeUpperCase"})
@Slf4j
public class CommUtils {
	
	
	public static final String CSV_COLUMN_SEPARATOR = ",";
	public static final String CSV_RN = "\r\n";
	public static final String CSV_CHAR_SET_NAME = "UTF-8";

	public static final String PARAMS_CREATE_DATE = "createDate";

	public static final String PARAMS_DATA_STATUS = "dataStatus";

	public static final String ID="id";

	public static final String ORDER_BY_CASE = "create_date DESC";

	public static final String STR_FORMAT = "000";

	public static final String SIMP_USER = "simpUser";

	/**定义script的正则表达式{或<script[^>]*?>[\\s\\S]*?<\\/script>**/
	public static final String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>";
	/**定义style的正则表达式{或<style[^>]*?>[\\s\\S]*?<\\/style>**/
	public static final String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>";
	/**定义HTML标签的正则表达式***/
	public static final String regEx_html = "<[^>]+>";
	/***定义一些特殊字符的正则表达式 如：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;***/
	public static final String regEx_special = "\\&[a-zA-Z]{1,10};";


	public static final Integer subMessageContent = 50;
	/**
	 * 替换 网页标签内容
	 * @param htmlString
	 * @return
	 */
	public static String replaceHtmlTag(String htmlStr){
		String textStr = "";
		Pattern p_script;
		Matcher m_script;
		Pattern p_style;
		Matcher m_style;
		Pattern p_html;
		Matcher m_html;
		Pattern p_special;
		Matcher m_special;
		try {
			p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
			m_script = p_script.matcher(htmlStr);
			htmlStr = m_script.replaceAll("");
			p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
			m_style = p_style.matcher(htmlStr);
			htmlStr = m_style.replaceAll("");
			p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
			m_html = p_html.matcher(htmlStr);
			htmlStr = m_html.replaceAll("");
			p_special = Pattern.compile(regEx_special, Pattern.CASE_INSENSITIVE);
			m_special = p_special.matcher(htmlStr);
			htmlStr = m_special.replaceAll("");
			textStr = htmlStr;
		}catch (Exception e){
			log.info(e.getMessage());
		}
		return textStr;
	}




	public static String haoAddOne(String liuShuiHao){
		Integer intHao = Integer.parseInt(liuShuiHao);
		intHao++;
		DecimalFormat df = new DecimalFormat(STR_FORMAT);
		return df.format(intHao);

	}

	/**
	 * 根据前端请求传的每页行数， 如前端传的该值是空或小于0，返回默认10行 Description: TODO param: pPageSize
	 * 
	 * return: int throws:
	 *
	 */
	public static int getPageSize(Integer pPageSize) {
		if (pPageSize != null) {
			return pPageSize;
		} else {
			return 10;
		}
	}
	
	public static ArrayList<String> readCsv(String filepath) {
		// CSV文件路径
        File csv = new File(filepath);
		//设置可读
        csv.setReadable(true);
		//设置可写
        csv.setWritable(true);
        BufferedReader br = null;
        try {
            br = new BufferedReader(new FileReader(csv));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        String line = "";
        String everyLine = "";
        ArrayList<String> allString = new ArrayList<>();
        try {
			// 读取到的内容给line变量
            while ((line = br.readLine()) != null)
            {
                everyLine = line;
                System.out.println(everyLine);
                allString.add(everyLine);
            }
            System.out.println("csv表格中所有行数：" + allString.size());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return allString;
        
    }
	
	public static List<Map<String, Object>> readDataByCsv(InputStream is, List<String> colNames, int startCnt,
			String pKeyName) {
		List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>();

		try {
			InputStreamReader isr = new InputStreamReader(is, CSV_CHAR_SET_NAME);
			ret = readDataByCsv(isr, colNames, startCnt, pKeyName);

		} catch (Exception ex) {
			log.error(ex.getMessage());
		}
		return ret;
	}

	public static List<Map<String, Object>> readDataByCsv(InputStream is, List<String> colNames, int startCnt) {
		List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>();

		try {

			InputStreamReader isr = new InputStreamReader(is, CSV_CHAR_SET_NAME);
			ret = readDataByCsv(isr, colNames, startCnt);

		} catch (Exception ex) {
			log.error(ex.getMessage());
		}
		return ret;
	}

	public static List<Map<String, Object>> readDataByCsv(InputStreamReader isr, List<String> colNames, int startCnt,
			String pKeyName) {
		List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>();

		try {

			List<List<String>> list = read4CSV(isr);

			if (startCnt < 1) {

			} else {
				list.remove(0);
			}
			

			for (List<String> tmp : list) {
				Map<String, Object> map = new HashMap<String, Object>();
				for (int i = 0; i < colNames.size(); i++) {
					map.put(colNames.get(i), tmp.get(i));
				}
				map.put(pKeyName, 0);

				ret.add(map);

				
			}

		} catch (Exception ex) {
			log.error(ex.getMessage());
		}
		return ret;
	}

	public static List<Map<String, Object>> readDataByCsv(InputStreamReader isr, List<String> colNames, int startCnt) {
		List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>();

		try {

			List<List<String>> list = read4CSV(isr);

			if (startCnt < 1) {

			} else {
				list.remove(0);
			}

			for (List<String> tmp : list) {
				Map<String, Object> map = new HashMap<String, Object>();

				for (int i = 0; i < colNames.size(); i++) {
					map.put(colNames.get(i), tmp.get(i));
				}

				ret.add(map);
			}

		} catch (Exception ex) {
			log.error(ex.getMessage());
		}
		return ret;
	}

	public static List<String> String2List(String str, String separator) {
		return Arrays.asList(str.split(separator));
	}

	public static List<List<String>> read4CSV(InputStreamReader isr) {
		List<List<String>> ret = new ArrayList<List<String>>();
		BufferedReader br = null;

		try {
			br = new BufferedReader(isr);
			String line = null;

			while ((line = br.readLine()) != null) {
				ret.add(Arrays.asList(line.split(CSV_COLUMN_SEPARATOR)));
			}

		} catch (Exception ex) {
			log.error(ex.getMessage());
		}
		return ret;
	}

	@SuppressWarnings("rawtypes")
	public static boolean exportCsvByObj(List dataList, List<String> colTitles, List<String> colNames,
			OutputStream os) {
		boolean ret = false;
		try {
			if (dataList != null) {
				List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
				for (Object obj : dataList) {
					list.add(bean2Map(obj));
				}

				ret = exportCsv(list, colTitles, colNames, os);
			}
		} catch (Exception ex) {
			log.error(ex.getMessage());
		}
		return ret;
	}
	
	
	public static <T> List<Map<String, Object>> listToListMap(List<T> list){
		List<Map<String, Object>> mlist = new ArrayList<Map<String, Object>>();
		for (Object obj : list) {
			mlist.add(bean2Map(obj));
		}
		return mlist;
	}
	
	/**
	 * 导出csv模板
	 * Description: TODO
	 * param: @param colTitles
	 * param: @param os
	 * param: @return
	 * return: boolean
	 * throws: 
	 *
	 */
	public static boolean exportCsvModel(List<String> colTitles,
			OutputStream os) {
		boolean ret = false;
		try {
			StringBuffer buf = new StringBuffer();

			for (String str : colTitles) {
				buf.append(str).append(CSV_COLUMN_SEPARATOR);
			}
			buf.append(CSV_RN);
			byte[] uft8bom = { (byte) 0xef, (byte) 0xbb, (byte) 0xbf };
			os.write(uft8bom);

			os.write(buf.toString().getBytes(CSV_CHAR_SET_NAME));
			os.flush();
			os.close();
			ret = true;
		} catch (Exception ex) {
			log.error(ex.getMessage());
		}
		return ret;
	}
	/****
	 * 导出CSV
	 * Description: TODO
	 * param: @param dataList
	 * param: @param colTitles
	 * param: @param colNames
	 * param: @param os
	 * param: @return
	 * return: boolean
	 * throws: 
	 *
	 */
	public static boolean exportCsv(List<Map<String, Object>> dataList, List<String> colTitles, List<String> colNames,
			OutputStream os) {
		boolean ret = false;
		try {
			StringBuffer buf = new StringBuffer();
			
			for (String str : colTitles) {
				buf.append(str).append(CSV_COLUMN_SEPARATOR);
			}

			buf.append(CSV_RN);

			if (dataList != null && dataList.size() > 0) {
				for (Map<String, Object> map : dataList) {
					for (String str : colNames) {
						buf.append(map.get(str)).append(CSV_COLUMN_SEPARATOR);
					}
					buf.append(CSV_RN);
				}
			}

			byte[] uft8bom = new byte[]{(byte)0xEF, (byte)0xBB, (byte)0xBF};
			os.write(uft8bom);
			os.write(buf.toString().getBytes(CSV_CHAR_SET_NAME));
			os.flush();
			os.close();
			ret = true;
		} catch (Exception ex) {
			log.error(ex.getMessage());
		}
		return ret;
	}
		/****
		 * 密码校验  不能出现中文
		 * Description: TODO
		 * param: @param str
		 * param: @return
		 * return: boolean
		 * throws: 
		 *
		 */
		public static boolean isLetterDigitOrChinese(String str) {
			String regex = "^([A-Z]|[a-z]|[0-9]|[`~!@#$%^&*()+=|{}':;',\\\\[\\\\].<>/?~！@#￥%……&*（）――+|{}【】‘；：”“'。，、？]){6,20}$";
		  return str.matches(regex);
		 }
		/****
		 * 输入校验不能出现特殊字符  只允许英文中文数字
		 * Description: TODO
		 * param: @param content
		 * param: @return
		 * return: boolean
		 * throws: 
		 *
		 */
		public static boolean isContentLetterDigitOrChinese(String content) {
			String regex="^[a-zA-Z0-9\u4E00-\u9FA5]+$";
			Pattern pattern = Pattern.compile(regex);
			Matcher match=pattern.matcher(content);
			return match.matches();
		}
		
		/*****
		 * 账户校验只允许  数字英文
		 * Description: TODO
		 * param: @param str
		 * param: @return
		 * return: boolean
		 * throws: 
		 *
		 */
		public static boolean isLetterDigit(String str) {
			  String regex = "^[a-z0-9A-Z]+$";
			  return str.matches(regex);
	    }
		
		
		
		
		/**
		 * 手机号码正则校验
		 * Description: TODO
		 * param: @param str
		 * param: @return
		 * return: boolean
		 * throws: 
		 *
		 */
		public static boolean isPhoneNumberDigit(String str) {
			String regex="((\\d{11})|^((\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1})|(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1}))$)";
			return str.matches(regex);
		}
		
		
//		/***
//		 * 各种电话
//		 * Description: TODO
//		 * param: @param str
//		 * param: @return
//		 * return: boolean
//		 * throws: 
//		 *
//		 */
//		public static boolean isTelDigit(String str) {
//			String regex=" ((\\d{11})|^((\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1})|(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1}))$)";
//			return str.matches(regex);
//		}
		/**
		 * Email 校验
		 * Description: TODO
		 * param: @param str
		 * param: @return
		 * return: boolean
		 * throws: 
		 *
		 */
		public static boolean isEmailDigit(String str) {
			String regex="^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
			 return str.matches(regex);
		}
	/**
	 * object Conversion to map Description: TODO param: bean
	 * 
	 * return: Map throws:
	 *
     * @return
     */
	@SuppressWarnings("unchecked")
	public static Map<String, Object> bean2Map(Object bean) {
		Map<String, Object> ret = null;

		@SuppressWarnings("unused")
		BeanInfo beanInfo = null;

		try {

			ret = new HashMap<String, Object>();

			String strJson = object2JSONStr(bean);

			if (!StringUtils.isBlank(strJson)) {
				Object obj = json2Bean(strJson, Map.class);
				ret = (Map<String, Object>) obj;
			}

		} catch (Exception ex) {
			log.error(ex.getMessage());
		} finally {

			beanInfo = null;
		}

		return ret;
	}
	public static Map<String, String> bean2StringMap(Object bean) {
		Map<String, String> ret = null;

		@SuppressWarnings("unused")
		BeanInfo beanInfo = null;

		try {

			ret = new HashMap<String, String>();

			String strJson = object2JSONStr(bean);

			if (!StringUtils.isBlank(strJson)) {
				Object obj = json2Bean(strJson, Map.class);
				ret = (Map<String, String>) obj;
			}

		} catch (Exception ex) {
			log.error(ex.getMessage());
		} finally {

			beanInfo = null;
		}

		return ret;
	}
	@SuppressWarnings("unchecked")
	public static <T>  Map<String, Object> bean2Map(Class<T> t) {
		Map<String, Object> ret = null;

		@SuppressWarnings("unused")
		BeanInfo beanInfo = null;

		try {

			ret = new HashMap<String, Object>();

			String strJson = object2JSONStr(t);

			if (!StringUtils.isBlank(strJson)) {
				Object obj = json2Bean(strJson, Map.class);
				ret = (Map<String, Object>) obj;
			}

		} catch (Exception ex) {
			log.error(ex.getMessage());
		} finally {

			beanInfo = null;
		}

		return ret;
	}
	@SuppressWarnings("unchecked")
	public static Object json2Bean(String jsonStr, @SuppressWarnings("rawtypes") Class cls) {
		Object ret = null;
		ObjectMapper mapper=new ObjectMapper();
		try {
			ret = mapper.readValue(jsonStr, cls);
		} catch (Exception ex) {
			log.error(ex.getMessage()+"\r\n"+jsonStr);
		} finally {

		}

		return ret;
	}
	public static String object2JSONStr(Object obj) {
		String ret = "";
		ObjectMapper mapper=new ObjectMapper();
		try{
			ret = mapper.writeValueAsString(obj);
//			ret = JSON.toJSONString(obj);
		} catch (Exception ex) {
			log.error(ex.getMessage());
		} finally {

		}
		return ret;
	}
	
	
//	public static Object json2Bean(String jsonStr) {
//		Object ret = null;
//
//		try {
//			ObjectMapper mapper=new ObjectMapper();
//			ret = mapper.readValue(jsonStr);
//			ret = JSON.parseObject(jsonStr);
//
//		} catch (Exception ex) {
//			log.error(ex.getMessage()+"\r\n"+jsonStr);
//		} finally {
//
//		}
//
//		return ret;
//	}
	 @SuppressWarnings("rawtypes")
		public static boolean checkColumn(Object t,String name){
	    	Class clz=t.getClass();
	    	Field[] fields=clz.getDeclaredFields();
	    	 
	    	boolean b=false;
	    	for (int i = 0; i < fields.length; i++) {
	    	    if(fields[i].getName().equals(name))
	    	    {
	    	        b=true;
	    	        break;
	    	    }
	    	}
	    	return b;
	    }

	
	/**
	 * 获取文件后缀
	 * Description: TODO param: fileName
	 * 
	 * return: String throws:
	 *
	 */
	public static String getFileSuffix(String fileName) {
		String ret = "";
		if (fileName.indexOf(".") > 0) {
			ret = fileName.substring(fileName.lastIndexOf(".") + 1);
		} else {
			log.info(fileName + "  the file name error..");
			ret="jpg";
		}

		return ret;
	}

	/**
	 * 检测文件目录是否存在不存在则创建该目录
	 * Description: TODO
	 * param: @param filepath
	 * return: void
	 * throws: 
	 *
	 */
	public static void judeDirExists(String filepath) {
			File file=new File(filepath);
			if (file.exists()) {
						if (file.isDirectory()) {
						                System.out.println("dir exists");
						} else {
								System.out.println("the same name file exists, can not create dir");
			           }
			        } else {
		             System.out.println("dir not exists, create it ...");
			            file.mkdir();
			         }
				
			     }
	public static Double parseDoublePoint2(Double number) {
		DecimalFormat df = new DecimalFormat("#.00");
		return Double.parseDouble(df.format(number));
	}
	
	
	
	public static <T> String getCacheKey(Class<T> clz,Map<String, Object> paramsMap) {
		String cacheKey=clz.getSimpleName();
		for (String key : paramsMap.keySet()) {
			cacheKey+="#"+key+"="+paramsMap.get(key);
		}
		return cacheKey;
	}
	
	/***
	 * 获取传入的对象所有不为空的参数
	 * @Description: TODO
	 * @param: @param model
	 * @param: @param clz
	 * @param: @return
	 * @return: Map<String,Object>
	 * throws: 
	 *
	 */
	public static <T> Map<String, Object> getParamsMap(T model,Class<T> clz){
		Map<String, Object> map = new HashMap<String, Object>();
		if(model!=null) {
			map=bean2Map(model);
			if (map.containsKey("dataStatus")) {
				if(map.get("dataStatus")==null) {
					map.put("dataStatus", 0);
				}
			}
			map=StringUtils.removeMapEmptyValue(map);
		}else {
			if(checkColumn(clz, "dataStatus")) {
				map.put("dataStatus", 0);
			}
		}
		return map;
	}

	public static <T> Map<String, String> getParamsStringMap(T model,Class<T> clz){
		Map<String, String> map = new HashMap<String, String>();
		if(model!=null) {
			map=bean2StringMap(model);
			if (map.containsKey("dataStatus")) {
				if(map.get("dataStatus")==null) {
					map.put("dataStatus", "0");
				}
			}
			map=StringUtils.removeStringMapEmptyValue(map);
		}else {
			if(checkColumn(clz, "dataStatus")) {
				map.put("dataStatus", "0");
			}
		}
		return map;
	}
	/**
	 * 检测对象是否包含某字段
	 * Description: TODO
	 * param: @param clz
	 * param: @param name
	 * param: @return
	 * return: boolean
	 * throws: 
	 *
	 */
	public static <T> boolean checkColumn(Class<T> clz,String name){
    	boolean b=false;
    	try {
			Object obj=clz.newInstance();
			Field[] fields=obj.getClass().getDeclaredFields();
	    	
	    	for (int i = 0; i < fields.length; i++) {
	    	    if(fields[i].getName().equals(name))
	    	    {
	    	        b=true;
	    	        break;
	    	    }
	    	}
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
    	return b;
    }
	
	public static boolean compare(String regx,String str) {
		Pattern p = Pattern.compile(".*"+regx+".*");
		Matcher m = p.matcher(str);
		boolean isValid = m.matches();
		return isValid;
	}
	
	
	public static String getCharct(InputStream is) {
		byte[] b = new byte[3];
		String charct="GBK";
        try {
			is.read(b);
			if (b[0] == -17 && b[1] == -69 && b[2] == -65) {
		      	  charct="UTF-8";
		        }
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
       return charct;
        
	}
	
	
	/**
	 * 根据数据创建本地文件
	 * Description: TODO
	 * param: @param filePath 
	 * param: @param title    中文表头
	 * param: @param colunms  当数据不为空时此值必须传入  且是数据的键值
	 * param: @param rows    数据可为空
	 * return: void
	 * throws: 
	 *
	 */
	public static void createLocalFile(String filePath,String[] title,String[] colunms,List<Map<String, Object>> rows) {
		File file=new File(filePath);
		if(!file.getParentFile().exists()) {
			file.getParentFile().mkdirs();
		}
		if(!file.exists()) {
			try {
				file.createNewFile();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		OutputStreamWriter osw=null;
		FileOutputStream fos=null;
		BufferedWriter bWriter=null;
		try {
			fos=new FileOutputStream(file);
			/**写入windows能识别的BOM头部**/
			fos.write(new byte[]{(byte)0xEF, (byte)0xBB, (byte)0xBF});
            osw=new OutputStreamWriter(fos,"utf-8");//写入输入文件
            bWriter=new BufferedWriter(osw);//写入缓存区
            /*写入表头*/
            for (int i = 0; i < title.length; i++) {
				String string = title[i];
				if(i==title.length-1) {
					bWriter.write(string+"\n");
				}else {
					bWriter.write(string+",");
				}
			}
            if(checkListIsNull(rows)) {
            	for (Map<String, Object> map : rows) {
					for (int i = 0; i < colunms.length; i++) {
						String key = colunms[i];
						if(i==colunms.length-1) {
							if(map.get(key)!=null) {
							bWriter.write(map.get(key).toString()+"\n");
							}else {
								bWriter.write(""+"\n");
							}
						}else {
							if(map.get(key)!=null) {
								bWriter.write(map.get(key).toString()+",");
							}else {
								bWriter.write(",");
							}
							
						}
					}
				}
            }
		
		} catch (FileNotFoundException e) {
			// TODO: handle exception
			System.out.println("找不到文件");
		}catch (IOException e) {
				// TODO: handle exception
				System.out.println("读取文件失败");
		}finally{
			try {
			bWriter.close();//关闭写入缓存区
			osw.close();//关闭写入文件内容
			fos.close();//关闭写入文件 
			} catch (IOException e) {
				// TODO: handle exception
				e.printStackTrace();
				log.error(e.getMessage());
				log.error(filePath);
			}
		}
		
	}
	
	public static boolean deleteFile(String filepath) {
		File file=new File(filepath);
		if(!file.isDirectory()&&file.exists()) {
			file.delete();
			return true;
		}
		return false;
	}
	
	public static boolean checkStrContains(String str,String ...strs) {
		for (String chars : strs) {
			if(str.equals(chars)) {
				return true;
			}
		}
		return false;
	}
	public static Double parseDouble(Double value,int fix) {
		NumberFormat nf = NumberFormat.getNumberInstance();
		// 保留两位小数
		nf.setMaximumFractionDigits(fix); 
		// 如果不需要四舍五入，可以使用RoundingMode.DOWN
		nf.setRoundingMode(RoundingMode.DOWN);
		return Double.parseDouble(nf.format(value));
	}
	/**
	 * 
	 * @Description: TODO
	 * @param: @param value
	 * @param: @param fix 格式为 ‘#.00’指定几个零则为几位
	 * @param: @return
	 * @return: Double
	 * throws: 
	 *
	 */
	public static Double parseDouble(Double value,String fix) {
		if(StringUtils.checkIsNulls(fix)) {
			fix="#.00";
		}
		DecimalFormat df = new DecimalFormat(fix);
		String str = df.format(value);
		return Double.parseDouble(str);
	}
	
	/*****
	 * 判断list 是否为空   不为空返回真  为空返回false
	 * @Description: TODO
	 * @param: @param checkList
	 * @param: @return
	 * @return: boolean
	 * throws: 
	 *
	 */
	public static <T> boolean checkListIsNull(List<T> checkList) {
		if(checkList!=null&&checkList.size()>0) {
			return true;
		}
		return false;
	}
	/**
     * 判断两个List内的元素是否相同
     *
     * @param list1
     * @param list2
     * @return
     */
    public static <T> boolean getDiffrent4(List<T> list1, List<T> list2) {
//        long st = System.nanoTime();
    	if(list1==null&&list2==null) {
    		return true;
    	}
    	if(list1!=null&&list1.size()>0&&list2!=null&&list2.size()>0) {
    	    Map<T, Integer> map = new HashMap<T, Integer>(list1.size() + list2.size());
            List<T> maxList = list1;
            List<T> minList = list2;
            if (list2.size() > list1.size()) {
                return false;
            }
            if (list2.size() < list1.size()) {
                return false;
            }
            int i=0;
            for (T s : maxList) {
                map.put(s, 1);
                i++;
            }
            int j=0;
            for (T s : minList) {
                Integer cc = map.get(s);
                if (cc != null) {
                    map.put(s, ++cc);
                    j++;
                 //说明出现了不一样的值
                }else {
                   return false;
                }
            }
            if(i==j) {
            	return true;
            }else {
            	return false;
            }
    	}else {
    		return false;
    	}
////        System.out.println("getDiffrent4 total times " + (System.nanoTime() - st));
//        return true;
    }
    
    public static String getDatafromFile(String Path) {
        
//        String Path="d:\\jsonFile\\" + fileName+ ".json";
           BufferedReader reader = null;
         String laststr = "";
           try {
             FileInputStream fileInputStream = new FileInputStream(Path);
              InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
               reader = new BufferedReader(inputStreamReader);
              String tempString = null;
            while ((tempString = reader.readLine()) != null) {
                 laststr += tempString;
             }
              reader.close();
          } catch (IOException e) {
            e.printStackTrace();
           } finally {
              if (reader != null) {
                  try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                   }
              }
          }
          return laststr;
      }
    
    public static String genRandomNumString(Integer length){
      //避免出错默认配置4位
      if (length==null) {
		length = 4;
      }
      if(StringUtils.checkIsNotNull(length)&&length<1) {
    	  length = 4 ;
      }
  	  int  maxNum = 36;
  	  int i;
  	  int count = 0;
  	  char[] str = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
  	    'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  	    'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };	  
  	  StringBuffer pwd = new StringBuffer("");
  	  Random r = new Random();
  	  while(count < length){
  	   i = Math.abs(r.nextInt(maxNum));   
  	   if (i >= 0 && i < str.length) {
  	    pwd.append(str[i]);
  	    count ++;
  	   }
  	  }
  	  return pwd.toString();
  	}
//	public static List<Map<String, String>> toListMap(String jsonString){
//		JSONArray jsonArray=JSONArray.fromObject(jsonString);
//		Iterator iterator = jsonArray.iterator();
//		List<Map<String, String>> result=new ArrayList<Map<String, String>>();
//		while (iterator.hasNext()) {
//			JSONObject jb = (JSONObject) iterator.next();
//			Iterator iterator2 = jb.keys();
//			Map<String, String> map=new HashMap<String,String>();
//			String key = null;
//			String value = null;
//			while (iterator2.hasNext()) {
//				key = (String) iterator2.next();
//				value = jb.getString(key);
//				map.put(key, value);
//			}
//			result.add(map);
//		}
//		return result;
//	}
}





